//
//  ButtonArrowView.swift
//  MyTest
//
//  Created by guanzhongwang on 2021/5/14.
//

import UIKit

class ButtonArrowView: UIView {
    private var arrow:UIImageView = UIImageView()
    private var tipLabel:UILabel = UILabel()
    private var titleLabel:UILabel = UILabel()
    init() {
        super.init(frame: .zero)
        self.createView()
    }
    private func createView(){
        backgroundColor = .white
        addSubview(titleLabel)
        titleLabel.snp.makeConstraints({
            $0.left.top.equalTo(15)
            $0.bottom.equalToSuperview().inset(15)
        })
        titleLabel.font  = Font_Size_16
        tipLabel.font = Font_Size_14
        tipLabel.textColor = .lightGray
        addSubview(tipLabel)
        tipLabel.snp.makeConstraints({
            $0.right.equalToSuperview().inset(30)
            $0.centerY.equalToSuperview()
        })
        let image = UIImage(named: "arrowright")?.withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
        arrow.tintColor = B999_TITLE_COLOR
        arrow.image = image
        arrow.tintColor = .lightGray
        addSubview(arrow)
        arrow.snp.makeConstraints({
            $0.centerY.equalToSuperview()
            $0.right.equalToSuperview().inset(5)
        })
        addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(viewTap)))
    }
    func binding(_ data:SetItemModel) {
        self.tipLabel.text = data.tip
        self.arrow.isHidden = data.hiddenArrow
        if(data.subTitle != ""){
            let text = data.title + "\n" + data.subTitle
            self.titleLabel.attributedText = text.getAttributedString(data.subTitle, subColor: B999_TITLE_COLOR, subFont: Font_Size_12, lineSpace: 5.0)
            titleLabel.numberOfLines = 2
        }else{
            self.titleLabel.text = data.title
            titleLabel.numberOfLines = 1
        }
    }
    @objc func viewTap(){
        
    }
    
    override func draw(_ rect: CGRect) {
        super.draw(rect)
        addBottomBorder()
    }
    required init?(coder: NSCoder) {
        fatalError()
    }

}
